import impart.random_num
import random

import main


#判断是不是终结者
def isBOSS(QQ):
    if int(QQ)%5 ==main.BOSS_num:
        result = True
        return result
    else:
        result = False
        return result

#玩家对战，传入两个玩家，返回一段文字，两个玩家player
def player_battle(playera,playerb):
    LengthADD = impart.random_num.random_LengthADD()  # 胜者增加，败者减少
    InjectionADD = impart.random_num.random_Injection()  # 败者注入增加量
    EXPADD = impart.random_num.random_EXPADD()  # 胜者增加经验
    pk_text = ""
    result = random.choice(["win", "loss"])
    if result == "win":
        #判断自己是不是终结者
        if isBOSS(playera.QQID):
            #是终结者
            playera.Length = playera.Length + LengthADD
            playera.EXP = playera.EXP + EXPADD
            playerb.TodayInjection = playerb.TodayInjection + InjectionADD
            playerb.TatallInjection = playerb.TatallInjection + InjectionADD
            playerb.Length = playerb.Length / 2
            pk_text = f"【{playera.QQID}】对【{playerb.QQID}】发起对决，获得胜利，更令人恐怖的是，你竟然是这个时段的牛牛终结者，你拥有直接把对方牛牛拦腰斩断的能力，对方迫不得已被你注入{round(InjectionADD, 2)}ml，你的牛牛增加{round(LengthADD, 2)}cm。【{playerb.QQID}】不堪受辱，牛牛被拦腰斩断，长度直接少了一半，乐。"
        else:
            playera.Length = playera.Length + LengthADD
            playera.EXP = playera.EXP + EXPADD
            playerb.TodayInjection = playerb.TodayInjection + InjectionADD
            playerb.TatallInjection = playerb.TatallInjection + InjectionADD
            playerb.Length = playerb.Length - LengthADD
            pk_text = f"【{playera.QQID}】对【{playerb.QQID}】发起对决，获得胜利，强行注入了{round(InjectionADD,2)}ml，牛牛增加{round(LengthADD,2)}cm。【{playerb.QQID}】不堪受辱，牛牛缩短{round(LengthADD,2)}cm，感觉被玩坏了。"
    if result == "loss":
        # 判断对方是不是终结者
        if isBOSS(playerb.QQID):
            # 是终结者
            playerb.Length = playerb.Length + LengthADD
            playera.EXP = playera.EXP + EXPADD
            playera.TodayInjection = playera.TodayInjection + InjectionADD
            playera.TatallInjection = playera.TatallInjection + InjectionADD
            playera.Length = playera.Length / 2
            pk_text = f"【{playera.QQID}】对【{playerb.QQID}】发起对决，却被撅翻在地，被强行注入了{round(InjectionADD,2)}ml，并且惊恐万分的发现，对方竟然是这个时段的牛牛终结者！即使疯狂抵抗，牛牛依然被对方拦腰斩断，长度缩减一半。【{playerb.QQID}】如有神助，牛牛增长{round(LengthADD,2)}cm！"
        else:
            playera.Length = playera.Length + LengthADD
            playera.EXP = playera.EXP + EXPADD
            playerb.TodayInjection = playerb.TodayInjection + InjectionADD
            playerb.TatallInjection = playerb.TatallInjection + InjectionADD
            playerb.Length = playerb.Length - LengthADD
            pk_text = f"【{playera.QQID}】对【{playerb.QQID}】发起对决，却被撅翻在地，被强行注入了{round(InjectionADD,2)}ml，不堪受辱，牛牛缩短{round(LengthADD,2)}cm。【{playerb.QQID}】如有神助，牛牛增长{round(LengthADD,2)}cm！"

    return pk_text,playera,playerb
